package com.job.learn.cuiyt.job.start;

import com.dangdang.ddframe.job.config.JobCoreConfiguration;
import com.dangdang.ddframe.job.config.simple.SimpleJobConfiguration;
import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.dangdang.ddframe.job.lite.config.LiteJobConfiguration;
import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import com.job.learn.cuiyt.job.FileBackUpJob;
/**
 * @author: cuiyutian1
 * @date: 2021/12/26 12:28
 * @description:
 */
public class FileBackUpJobStart {


    private static int PORT = 2181;
    private static String CONNECTION = "127.0.0.1:"+ PORT;
    private static String NAME_SPACE = "easy-job";


    public static void main(String[] args) {
        CoordinatorRegistryCenter center = setUpRegister();
        startJob(center);
    }

    private static CoordinatorRegistryCenter setUpRegister(){
        ZookeeperConfiguration configuration = new ZookeeperConfiguration(CONNECTION, NAME_SPACE);
        configuration.setSessionTimeoutMilliseconds(100);
        ZookeeperRegistryCenter center = new ZookeeperRegistryCenter(configuration);
        center.init();
        return center;
    }
    private static void startJob(CoordinatorRegistryCenter center){
        JobCoreConfiguration build = JobCoreConfiguration.newBuilder("files-job", "0/3 * * * * ?", 2).build();
        SimpleJobConfiguration configuration = new SimpleJobConfiguration(build, FileBackUpJob.class.getCanonicalName());
        new JobScheduler(center, LiteJobConfiguration.newBuilder(configuration).overwrite(true).build()).init();
    }


}
